window.onload = function() {
//	var lis = document.getElementById("index-nav").getElementsByTagName("li");
//
//	//var divs = document.getElementById("bj").getElementsByTagName("h6");
//
//	for (var i = 0; i < lis.length; i++) {
//		lis[i].id = i;
//		lis[i].onclick = function() {
//			for (var j = 0; j < lis.length; j++) {
//				lis[j].className = "";
//				this.className = "select";
//			}
///*			for (var j = 0; j < divs.length; j++) {
//				//divs[j].style.display = "none";
//				lis[this.id].style.display = "block";
//			}*/
//		};
//	}

};
/**
 * 定义全局变量，用于判断在线/离线
 **/
//var online = navigator.onLine;

/**
 * 定义全局变量，立案机构ID
 **/
//var organId = $.cookie("organId");
//
//var organName = $.cookie("organName");
//
//
//var departId = $.cookie("departId");
//
//var departName = $.cookie("departName");
//
//var xzqhId = $.cookie("xzqhId");
//
//var xzqhName = $.cookie("xzqhName");
//
//var userId = $.cookie("userId");
//
//var userName = $.cookie("userName");


$(document).ready(function(){

    /**
     *首页
     */
    $("#sy").bind("click",function(){

        if($('#main').children("div").attr("id") == "handle"){
            $.messager.confirm('提示框', '请注意保存未保存的文书!', function(r){
                if (r){
                    $("#main").removeClass("panel-noscroll");
                    $("#main").load("shouye.html",function(){
                        syClick();
                    });
                }
            });
        }else{
            $("#main").removeClass("panel-noscroll");
            $("#main").load("shouye.html",function(){
                syClick();
            });
        }
    });

    /**
     *案件中心载入案件列表
     */
    $("#ajzx").bind("click",function(){
        if($('#main').children("div").attr("id") == "handle"){
            $.messager.confirm('提示框', '请注意保存未保存的文书!', function(r){
                if (r){
                    $("#main").load("../register/list.html",function(){
                        $("#handle_link").text('浏览');
                        $("#report").hide();
                        $("#xlsexport").hide();
                        $("#pdfexport").hide();
                        $("#operate_flag").val("ajzx");
                        initCaseeList();
                    });
                }
            });
        }else{
            $("#main").load("../register/list.html",function(){
                $("#handle_link").text('浏览');
                $("#report").hide();
                $("#xlsexport").hide();
                $("#pdfexport").hide();
                $("#operate_flag").val("ajzx");
                initCaseeList();
            });
        }
    });

    $("#tjfx").bind("click",function(){
        if($('#main').children("div").attr("id") == "handle"){
            $.messager.confirm('提示框', '请注意保存未保存的文书!', function(r){
                if (r){
                    $("#main").load("../register/list.html",function(){
                        $("#reload_link").hide();
                        $("#edit_link").hide();
                        $("#handle_link").hide();
                        $("#return_link").hide();
                        $("#operate_flag").val("");
                        initCaseeList();
                    });
                }
            });
        }else{
            $("#main").load("../register/list.html",function(){
                $("#reload_link").hide();
                $("#edit_link").hide();
                $("#handle_link").hide();
                $("#return_link").hide();
                $("#operate_flag").val("");
                initCaseeList();
            });
        }
    });
});


window.businesskey;
function addTab(options){
    window.businesskey = options.businesskey;
    var t = $("#index_tabs");
    if(t.tabs("exists",options.title)){
        //t.tabs("select",options.title);
        t.tabs("close",options.title);
        t.tabs("add",options);
    }else{
        t.tabs("add",options);
    }
}

function addTab1(){
    var tdate = new Date().getTime();
    var t = $("#index_tabs");
    var options = {
        title:'法律法规',
        //../html/lawsbook/zhrmghgglf/index.html#samples/steve-jobs
        content : '<iframe id="if" application="yes" scrolling="no" frameborder="0"  src="../html/lawsbook/index.html?t='+tdate+'" style="width:100%;height:100%;"></iframe>',
        closable : true
    }
    if(t.tabs("exists",options.title)){
        t.tabs("select",options.title);
    }else{
        t.tabs("add",options);
    }
}

function addTab2(){
    var tdate = new Date().getTime();
    var t = $("#index_tabs");
    var options = {
        title:'视频教程',
        content : '<iframe id="if" application="yes" scrolling="no" frameborder="0"  src="../html/lawsbook/video.html?t='+tdate+'" style="width:100%;height:100%;" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>',
        closable : true
    }
    if(t.tabs("exists",options.title)){
        t.tabs("select",options.title);
    }else{
        t.tabs("add",options);
    }
}

//扫描件上传[卷宗归档]
var scan_upload = function(wsname,form_id,case_id){
    var dynamic_dialog_updateload  = $("<div/>").dialog({
        title: wsname+'扫描件上传',
        href: getContextPath()+'/lzproof/scan_upload?case_id='+case_id+'&form_id='+form_id,
        border: true,
        resizable: true,//定义对话框是否可调整尺寸。
        maximized: true,//默认最大化
        width : 800,
        height: 500,
        modal: false,
        onClose:function(){
            $(this).dialog('destroy');
        }
    });
}
window.scan_upload = scan_upload;

function getContextPath(){
    return "http://localhost:8080/";
}


var loginOut = function(){
    $.ajax({
        type : "post",
        url  : getContextPath() + "/user/logout",
        dataType : "json",
        success : function(data) {
            if(data.success){
                self.location = getContextPath() + '/user/loginTo';
            }
        }
    });
}

function editCurrentUserPwd() {
    parent.$.modalDialog({
        title : '修改密码',
        width : 400,
        height : 250,
        href : getContextPath() + '/user/editCurrentUserPwdPage',
        buttons : [ {
            text : '提交',
            handler : function() {
                var f = parent.$.modalDialog.handler
                    .find('#editCurrentUserPwdForm');
                f.submit();
            }
        } ]
    });
}

function downs() {
    var dynamic_dialo112g  = $("<div/>").dialog({
        title:'资料下载',
        href : getContextPath() + '/html/zlxz/index.html?t='+new Date().getTime(),
        width:1100,
        height:500,
        closed: false,
        cache: false,
        onClose:function(){
            $(this).dialog('destroy');
        }
    });
}

function downApp() {
    var dynamic_dialo112g  = $("<div/>").dialog({
        title:'二维码',
        href : getContextPath() + '/html/zlxz/q.html?t='+new Date().getTime(),
        width:400,
        height:450,
        closed: false,
        cache: false,
        onClose:function(){
            $(this).dialog('destroy');
        }
    });
}



function syClick(){
    //findOrganZfmlByOrganIdOffLine(organId,initZfmlLi);
    /**
     * 黑名单 载入黑名单列表页面
     */
    $("#blacklistQuery").click(function(){
        if(online){
            $("#main").load("blacklist.html",function(){
                $("#list").attr('src',getContextPath()+"/jsp/case/blacklist/black.jsp");
                $("#list").bind('load',function(){
                    $(window.parent.frames["blacklistIframe"].document).find("#datagrid-toolbar #add_link").hide();
                    $(window.parent.frames["blacklistIframe"].document).find("#datagrid-toolbar #edit_link").hide();
                    $(window.parent.frames["blacklistIframe"].document).find("#datagrid-toolbar #delete_link").hide();
                });
            });
        }
    });
    /**
     * 案件接入页面
     */
    $("#inputcaseaccess").click(function(){
        if(online){
            $("#main").load("../query/caseaccess.html",function(){

            });
        }
    });
    $("#illegalTypeCode").click(function(){
        if(online){
            $("#main").load("../register/illegalTypeCode.html",function(){
//			openIllegalTypeCodeDialog();
            });
        }
    });
    /**
     * 信息查验页面
     */
    $("#info-check").click(function(){
        if(online){
            ownerQuery =  $.cookie("owner");
            ownerPageQuery = $.cookie("ownerPage");
            ownerPageNewQuery = $.cookie("ownerPageNew");
            vehicleQuery = $.cookie("vehicle");
            vehiclePageQuery=$.cookie("vehiclePage");
            vehiclePageNewQuery=$.cookie("vehiclePageNew");
            partyQuery= $.cookie("party");
            partyPageQuery=$.cookie("partyPage");
            partyPageNewQuery=$.cookie("partyPageNew");
            shipPartyPageNewQuery=$.cookie("shipPartyPageNew");
            shipPartyQuery=$.cookie("shipParty");
            shipPageNewQuery=$.cookie("shipPageNew");
            shipQuery=$.cookie("ship");
            $("#main").removeClass("panel-noscroll");
            $("#main").load("../query/info-check.html",function(){

            });
        }
    });




    $("#main").on('click', '#myWait' ,function(e){
        $("#main").removeClass("panel-noscroll");
        $("#main").load("../html/1.html",function(){

        });
    });

    $("#myWait1").click(function(){
        alert("123");
    });
    $(document.body).on('click', '#data_dic' ,function(e){
        $("#main").removeClass("panel-noscroll");
        $("#main").load("http://192.168.0.102:8080/aps/dd/dd",function(){

        });
    });

    $(document.body).on('click', '#sy' ,function(e){
        $("#main").removeClass("panel-noscroll");
        $("#main").load("../html/shouye.html",function(){

        });
    });



    if(online){

    }

    $("#caseQuickSousuo").unbind('click').bind('click',function(){
        var casequick_= $("#caseQuick").val();
        if(casequick_ == '结案'){
            $("#main").load("../register/list.html",function(){
                $("#ajzx li").trigger("click");
                $("#handle_link").text('浏览');
                $("#report").hide();
                $("#operate_flag").val("ajzx");
                initCaseeList();
            });
        }else{
            $("#th").hide();
            $("#main").load("../register/list.html",function(){
                $("#gzt li").trigger("click");
                $("#noJa").val("结案");
                $("#report").hide();
                initCaseeList();
            });
        }

    });

}

/**
 * 设置登录密码
 */
function changePassWord(){
    $('#changePassWordDialog').dialog({
        title: '设置离线登陆密码',
        width: 400,
        height: 200,
        inline:false,
        closed: false,
        cache: false,
        modal: true,
        content:"<div style='margin:30px'><div style='padding-bottom:5px'>登陆密码：<input id='password' class='easyui-textbox' type='password' style='width:60%;height:30px;padding:12px' data-options='required:true,validType:\"length[8,20]\",missingMessage:\"登陆密码必须填写\",invalidMessage:\"不能超过16个字符！\"'></div><div>确认密码：<input class='easyui-textbox' id='pwd' type='password' style='width:60%;height:30px;padding:12px' data-options='required:true,missingMessage:\"登陆密码必须填写\",validType:\"equalTo[password]\"'></div></div>",
        buttons: [{
            text:'确定',
            iconCls:'icon-ok',
            handler:function(){
                var password = $("#password").val();
                var pwd = $("#pwd").val();
                if($.trim(password).length==0){
                    message("登陆密码不能为空");
                    return;
                }
                if($.trim(pwd).length==0){
                    message("确认密码不能为空");
                    return;
                }
                if($.trim(password) != $.trim(pwd)){
                    message("两次输入密码不一致");
                    return;
                }
                changePassword(userId,hex_md5(password));
                $('#changePassWordDialog').dialog('close');
            }
        },{
            text:'取消',
            iconCls:'icon-cancel',
            handler:function(){
                $('#changePassWordDialog').dialog('close');
            }
        }]
    });
    $('#changePassWordDialog').dialog("center");
}


/**
 * 创建表
 */
function createTable() {
    findCaseBasicInfoById();

}

/**
 * app下载
 */
function uploadTwo(){
    $('#uploadTwoDialog').dialog({
        title: 'app',
        width: 300,
        height: 320,
        inline:false,
        closed: false,
        cache: false,
        modal: true,
        content:"<img src='../../../images/yn_zhxtphone.png'/>"
    });
}

/**
 * 在线待办事项
 *
 */
function findCaseCount() {
    $("#th").empty();
    $.ajax({
        type : "get",
        url  : getContextPath() + "/caseBasicInfo/findCount",
        data : {
            organId : organId
        },
        dataType : "json",
        success : function(data) {
            if (data.result == 'fail') {
                message(data.errorCode + ":" + data.errorMessage);
                return;
            }
            if (data.result == 'success') {
                if(data.content == 0){
                    return;
                }
                $("#th").append(data.content);
                $("#th").show();
            }
        }
    });
}

/**
 * 数据修改
 */
function updata() {
    $.messager.progress({
        msg:'正在加载数据...'
    });
    getData();
}

/**
 * 根据机构ID初始化执法门类
 */
function initZfmlLi(data){
    if(data==null|| data.length<=0){
        return;
    }
    $("div .con-two-con").html("");
    var size=data.length;
    var content="";
    if(size<5){
        $.each(data,function(index,item){
            content+= "<li><a id="+ item.zfmlId+" href='#'><img src='../images/"+item.zfmlId+".png'><p>"+item.zfml+"</p></a></li>";
        });
    }else{
        $.each(data,function(index,item){
            if((index<=4 ||index>5)&& index<=size-1){
                content+="<li><a id="+ item.zfmlId+" href='#'><img src='../images/"+item.zfmlId+".png'><p>"+item.zfml+"</p></a></li>";
            }
            if(index==5){
                content+="</ul><ul class='erpai'><li><a id="+ item.zfmlId+" href='#'><img src='../images/"+item.zfmlId+".png'><p>"+item.zfml+"</p></a></li>";
            }
        });
    }
    $("div .con-two-con").append("<ul class='yipai'>"+content+"</ul>");
    loadZfmlHtml();
}

/**
 *公路路政载入案件登记页面
 */
function loadZfmlHtml(){
    $("div .con-two-con a").click(function(){
        var id=$(this).attr("id");
        $.cookie('zfml_Id',id,{expires : 7,path : '/'});
        $("#main").load("../register/caseBasicInfoInput.html",function(){
            $("#main").removeClass("panel-noscroll");
            findDrawerById(id, initCase);
        });
    });
}

